import request from '@/utils/http'

// 获取当前角色已授权的模块Code（即根节点）-前端
export function getDaMoKuaiQuanXian(data) {
  return request.request({
    url: '/api/v3.1/business/menu-units/module-menu',
    method: 'get',
    data
  })
}
// 获取当前登录用户的已分配菜单的CODE。-前端 前端需要在此基础上增加如下逻辑： 如果当前登录用户的角色是admin，则需要在该返回数组的基础上增加权限管理相关页面的code。
export function getyongHuZhanShiCaiDan() {
  return request.request<string[]>({
    url: '/api/v3.1/business/menu-units/menu-units-by-current-user',
    method: 'get'
  })
}

// 根据角色Id获取已分配的菜单数组-前端
export function getJueShecYiFenPeiCaiDan(data) {
  return request.request({
    url: '/api/v3.1/business/menu-units/menu-units-by-role',
    method: 'get',
    data
  })
}

// 获取admin角色所有的菜单tree
export function getQuanBuCaiDan(data) {
  return request.request({
    url: '/api/v3.1/business/menu-units/admin-menu',
    method: 'get',
    data
  })
}

// 修改角色的菜单-前端
export function postXiuGaiJueSheCaiDan(data) {
  return request.request({
    url: '/api/v3.1/business/menu-units/menu-units-asso-role',
    method: 'post',
    data
  })
}

// // 获取登录人的基本信息
// export function getQuanBuCaiDan(data) {
//   return request.request({
//     url: '/api/identity/GetUserInfoByToken',
//     method: 'get',
//     data
//   });
// }

// 获取角色list列表
export function getJueSheList() {
  return request.request({
    url: '/api/identity/roles/all',
    method: 'get'
  })
}

// 创建角色
export function postAddJueShe(data) {
  return request.request({
    url: '/api/identity/roles',
    method: 'post',
    data
  })
}

// 修改角色基本信息
export function putJueSheXinXi(data) {
  return request.request({
    url: '/api/identity/roles/' + data.id,
    method: 'put'
  })
}

// 删除角色
export function deleteJueShe(data) {
  return request.request({
    url: '/api/identity/roles/' + data.id,
    method: 'delete'
  })
}

// 获取用户list列表
export function getCanDanYongHuList(data) {
  return request.request({
    url: '/api/identity/users?MaxResultCount=1000',
    method: 'get',
    data
  })
}

// 创建用户
export function postAddCanDanYongHu(data) {
  return request.request({
    url: '/api/identity/users',
    method: 'post',
    data
  })
}

// 修改用户基本信息
export function putCanDanYongHuXinXi(id, data) {
  return request.request({
    url: '/api/identity/users/' + id,
    method: 'put',
    data
  })
}

// 删除用户
export function deleteCanDanYongHu(id) {
  return request.request({
    url: '/api/identity/users/' + id,
    method: 'delete'
  })
}

// 获取用户的角色
export function getYongHuJueShe(data) {
  return request.request({
    url: '/api/identity/users/' + data.id + '/roles',
    method: 'get'
  })
}

// 修改用户的角色
export function putYongHuJueShe(data) {
  return request.request({
    url: '/api/identity/users/' + data.id + '/roles',
    method: 'put'
  })
}
